use std::char;

pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut number = parse_num(num_str);
    let mut res = String::new();
    while number > 0 {
        let digit = number % to_base;
        number /= to_base;
        res.push(char::from_digit(digit, to_base).unwrap());
    }
    res.chars().rev().collect()
}

fn parse_num(num_str: &str) -> u32 {
    let (number, base) = num_str.split_at(num_str.find('(').unwrap());
    let base: u32 = base[1..base.len() - 1].parse().unwrap();
    let mut num = 0;
    for c in number.chars() {
        num = num * base + c.to_digit(base).unwrap();
    }
    num
}
